package cn.com.fuhuitong.main.mine.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.app.BaseApplication
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.home.entity.CharityListResponse
import cn.com.fuhuitong.main.home.entity.HomeResponse
import cn.com.fuhuitong.main.home.mode.HomeManager
import cn.com.fuhuitong.main.host.entity.ConfigResponse
import cn.com.fuhuitong.main.mine.entity.*
import cn.com.fuhuitong.main.mine.mode.MineManager
import cn.com.fuhuitong.main.order.mode.OrderManager
import io.reactivex.disposables.Disposable

class WithdrawViewModel(application: Application) : BaseViewModel(application) {


    private val mineManager: MineManager = MineManager()

    val withdrawListDataLiveData = MutableLiveData<HttpResponse<WithdrawListResponse>>()

    val withdrawConfigDataLiveData = MutableLiveData<HttpResponse<WithdrawConfigResponse>>()

    val baseDataLiveData = MutableLiveData<HttpResponse<BaseResponse>>()

    private var page: Int = 1
    private var limit: Int = 500


    /**
     * 申请提现
     */
    fun addCash(entity: WithdrawEntity) {
        val listener =
            object :
                ViewModelSubscribeListener<BaseResponse>(baseDataLiveData) {}
        val addCashDisposable: Disposable = mineManager.addCash(
            BaseApplication.userToken(), entity, listener
        )
        dispose.add(addCashDisposable)
    }


    /**
     * 申请提现
     */
    fun addStoreCash(entity: WithdrawEntity) {
        val listener =
            object :
                ViewModelSubscribeListener<BaseResponse>(baseDataLiveData) {}
        val addCashDisposable: Disposable = mineManager.addStoreCash(
            BaseApplication.userToken(), entity, listener
        )
        dispose.add(addCashDisposable)
    }

    /**
     * 提现记录
     */
    fun cashList() {
        val listener =
            object :
                ViewModelSubscribeListener<WithdrawListResponse>(withdrawListDataLiveData) {}
        val cashListDisposable: Disposable = mineManager.cashList(
            BaseApplication.userToken(), page.toString(), limit.toString(), listener
        )
        dispose.add(cashListDisposable)
    }

    /**
     * 提现记录
     */
    fun cashStoreList() {
        val listener =
            object :
                ViewModelSubscribeListener<WithdrawListResponse>(withdrawListDataLiveData) {}
        val cashListDisposable: Disposable = mineManager.cashStoreList(
            BaseApplication.userToken(), page.toString(), limit.toString(), listener
        )
        dispose.add(cashListDisposable)
    }

    /**
     * 提现配置
     */
    fun cashPrice() {
        val listener =
            object :
                ViewModelSubscribeListener<WithdrawConfigResponse>(withdrawConfigDataLiveData) {}
        val cashPriceDisposable: Disposable = mineManager.cashPrice(
            BaseApplication.userToken(), listener
        )
        dispose.add(cashPriceDisposable)
    }

    /**
     * 提现配置
     */
    fun cashStorePrice() {
        val listener =
            object :
                ViewModelSubscribeListener<WithdrawConfigResponse>(withdrawConfigDataLiveData) {}
        val cashPriceDisposable: Disposable = mineManager.cashStorePrice(
            BaseApplication.userToken(), listener
        )
        dispose.add(cashPriceDisposable)
    }



    private val homeManager: HomeManager = HomeManager()

    val configDataLiveData = MutableLiveData<HttpResponse<ConfigResponse>>()

    /**
     * 获取配置信息
     * */
    fun configValue(name: Array<String>) {
        val listener =
            object : ViewModelSubscribeListener<ConfigResponse>(configDataLiveData) {}
        val configValueDisposable: Disposable = homeManager.configValue(name,listener)
        dispose.add(configValueDisposable)
    }

}